package com.briup.mt.service.impl;

import com.briup.mt.bean.Comment;
import com.briup.mt.bean.CommentExample;
import com.briup.mt.dao.CommentMapper;
import com.briup.mt.service.ICommentService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Resource
    private CommentMapper commentMapper;

    @Override
    public List<Comment> query(Long id) {
        CommentExample example=new CommentExample();
        if(!StringUtils.isEmpty(id)){
            example.createCriteria().andIdEqualTo(id);
        }
        List<Comment> list=commentMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Comment comment) {
            if (comment.getId() == null) {
                comment.setCommentTime(new Date().getTime());
                commentMapper.insert(comment);
            } else {
                commentMapper.updateByPrimaryKey(comment);
            }
    }
    @Override
    public void deleteById(long id) {
        commentMapper.deleteByPrimaryKey(id);
    }
    }